import touch from '@/mixin/prototype/touch';

function curry(fn,context){
	var outerArgs = Array.prototype.slice.call(arguments,2);
	return function(){
		var innerArgs = Array.prototype.slice.call(arguments);
		var finalArgs = outerArgs.concat(innerArgs);
		return fn.apply(context,finalArgs); 
	}
}

export default {
	//指令第一次绑定到元素 oldVnode 的属性: tag:'',elm:undefined
	bind(el,binding,vnode,oldVnode){
		//存储实例
		el._touch = touch(el);
		//绑定事件
		el._touch.on(Object.keys(binding.modifiers).join(' '),curry(binding.value,el._touch,el,binding.arg));
	},
	//被绑定元素插入父节点时
	inserted(el,binding,vnode,oldVnode){
		
	},
	componentUpdated(el,binding,vnode,oldVnode){
		
	},
	//解除事件
	unbind(el,binding,vnode,oldVnode){
		el._touch.remove(Object.keys(binding.modifiers).join(' '));
		delete el._touch;
	}
};